package com.hdjk.view.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.liangmutian.mypicker.DateUtil;
import com.hdjk.view.R;
import com.hdjk.view.entity.UserEntity;

import java.util.List;

/**
 * Created by sxy on 2017/11/3.
 */

public class RecommendListAdapter extends BaseAdapter {
    private List<UserEntity> mList;
    private Context mContext;

    public RecommendListAdapter(Context context) {
        mContext = context;
    }

    public void setDataList(List<UserEntity> list) {
        mList = list;
    }

    @Override
    public int getCount() {
        return mList != null ? mList.size() : 0;
    }

    @Override
    public UserEntity getItem(int position) {
        return mList != null ? mList.get(position) : null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Holder holder;
        if (convertView == null) {
            holder = new Holder();
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_recommend_list, null);
            holder.tv_name = (TextView) convertView.findViewById(R.id.tv_name);
            holder.tv_date = (TextView) convertView.findViewById(R.id.tv_date);
            convertView.setTag(holder);
        } else {
            holder = (Holder) convertView.getTag();
        }
        UserEntity entity = mList.get(position);
        holder.tv_name.setText(entity.getName());
        holder.tv_date.setText(DateUtil.formatDate(entity.getCreateTime(),DateUtil.ymd));
        return convertView;
    }

    class Holder {
        TextView tv_name;
        TextView tv_date;
    }
}
